package com.chen.nongansampling.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

public class StorageUtil {
    public static void StoragePasswordAndAccount(String account, String psw, Context context) {
        if (account != "" && psw != "") {
            SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            //步骤3：将获取过来的值放入文件
            editor.putString("account", account);
            editor.putString("password", psw);
            editor.commit();
            setLoginStatus(context,true);

        }
    }

    public static Boolean getLoginStatus(Context context) {
        //自动登录
        SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
        Boolean status = sharedPreferences.getBoolean("status", false);
        //步骤3：将获取过来的值放入文件
        return status;

    }

    public static String getAccount(Context context) {

        SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
        String s = sharedPreferences.getString("account", "");
        //步骤3：将获取过来的值放入文件
        return s;

    }


    public static String getPassword(Context context) {

        SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
 //       Boolean status = sharedPreferences.getBoolean("password", false);

        String s = sharedPreferences.getString("password", "");

        //步骤3：将获取过来的值放入文件
        return s;

    }


    public static void setLoginStatus(Context context, Boolean status) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        //步骤3：将获取过来的值放入文件
        editor.putBoolean("status", status);
        editor.commit();
    }

    public static void setAccountPkId(Context context,String pkid) {

        try {
            SharedPreferences sharedPreferences= context.getSharedPreferences("data", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            String ip=sharedPreferences.getString("pkid",pkid);
            editor.putString("pkid", pkid);
            editor.commit();
        }catch (Exception e)
        {
            Log.d("pkid",e.toString());
        }

    }

    public static String getAccountPkId(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
        String pkid = sharedPreferences.getString("pkid", "1");
        //步骤3：将获取过来的值放入文件
        return pkid;

    }



}





